package com.auto.api.core.type.json.yapi;

import com.auto.api.common.utils.JsonMapper;
import com.auto.api.core.type.json.AbstractTypeHandler;
import com.auto.api.core.type.json.JsonTypeHandler;
import java.util.HashMap;
import java.util.Map;
import org.springframework.core.ResolvableType;

/**
 * @program:
 * @description: 类型转换接口
 * @author: liangshf
 * @create: 2020-09-24
 */
public abstract class AbstractApiResultJsonTypeHandler extends AbstractTypeHandler<Map> implements JsonTypeHandler {

    @Override
    public Map getResultInstance() {
        return new HashMap();
    }

    /**
     * 根据类型获取默认Json
     * @return String
     */
    @Override
    public String doResultJson(ResolvableType resolvableType, Map resultMap){
        getResultJson(resolvableType, resultMap);
        Map root = new HashMap();
        root.put("type", "object");
        root.put("title", "object result");
        root.put("properties", resultMap);
        return JsonMapper.toJson(root);
    }

    abstract String getResultJson(ResolvableType resolvableType, Map resultMap);
}
